﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using EluZSProvider;
using Antu.Core.Services;
using System.Data;

namespace WebSys.UI.Control.ZhengShou.OfficeFlow
{
    public class ZS_AddFamily:Page
    {
        protected global::System.Web.UI.WebControls.DropDownList ddl关系;
        protected global::System.Web.UI.WebControls.DropDownList ddl证件类型;
        protected global::System.Web.UI.WebControls.DropDownList ddlIS_ZFBZ;
        protected global::System.Web.UI.WebControls.DropDownList ddlIS_NOTICEPERSON;
        protected global::System.Web.UI.WebControls.DropDownList ddl性别;
        protected global::System.Web.UI.WebControls.Panel Panel1;
        protected global::System.Web.UI.WebControls.Button btnok;
        protected global::Antu.WebControls.MPPersistence PersistenceControl1;
        protected global::System.Web.UI.WebControls.TextBox txtSID;
        protected global::System.Web.UI.WebControls.TextBox txtID;
        protected global::System.Web.UI.WebControls.TextBox txtHZID;
        protected global::System.Web.UI.WebControls.TextBox txtTABLENAME;
        protected global::System.Web.UI.WebControls.TextBox txt姓名;
        protected global::System.Web.UI.WebControls.TextBox txt证件号码;
        protected global::System.Web.UI.WebControls.TextBox txt申请类型;
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (!IsPostBack)
            {
                BindDll();
                PersistenceControl1.Table = "AT_FAMILY";
                PersistenceControl1.Key = "ID";
                PersistenceControl1.KeyValue = Request["ID"];
                PersistenceControl1.ConnStr = _EluZSDataProvider.GetConnectionString();//数据库链接字符串
            }
            PersistenceControl1.BindControl = Panel1;
            if (string.IsNullOrEmpty(Request["ID"]))
            {
                if (string.IsNullOrEmpty(Request["HZID"]))
                {
                    txtHZID.Text = Request["HZID"].ToString();
                } if (string.IsNullOrEmpty(Request["SID"]))
                {
                    txtSID.Text = Request["SID"];
                } if (string.IsNullOrEmpty(Request["tablename"]))
                {
                    txtTABLENAME.Text = Request["tablename"].ToString();
                } if (string.IsNullOrEmpty(Request["sqtype"]))
                {
                    string sqtype = Request["sqtype"].ToString();
                    if (sqtype == "1")
                    {
                        txt申请类型.Text = "浦口区被拆迁住房困难户购买经济适用住房";
                    }
                }
            }
            

        }

        protected void BindDll()
        {
            ddl关系.DataSource = _EluZSDataProvider.GetParamYB("称谓", "");
            ddl关系.DataTextField = "keyname";
            ddl关系.DataValueField = "keyvalue";
            ddl关系.DataBind();
            ddl证件类型.DataSource = _EluZSDataProvider.GetParamYB("证件类型", "");
            ddl证件类型.DataTextField = "keyname";
            ddl证件类型.DataValueField = "keyname";
            ddl证件类型.DataBind();
            ddlIS_ZFBZ.DataSource = _EluZSDataProvider.GetParamYB("是否享受保障", "");
            ddlIS_ZFBZ.DataTextField = "keyname";
            ddlIS_ZFBZ.DataValueField = "keyvalue";
            ddlIS_ZFBZ.DataBind();
            ddlIS_NOTICEPERSON.DataSource = _EluZSDataProvider.GetParamYB("是否是通知书成员", "");
            ddlIS_NOTICEPERSON.DataTextField = "keyname";
            ddlIS_NOTICEPERSON.DataValueField = "keyvalue";
            ddlIS_NOTICEPERSON.DataBind();
            ddl性别.DataSource = _EluZSDataProvider.GetParamYB("性别", "");
            ddl性别.DataTextField = "keyname";
            ddl性别.DataValueField = "keyname";
            ddl性别.DataBind();
        }
       

        /// <summary>
        /// 保存事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btnok_Click(object sender, EventArgs e)
        {
            //检查户主是否只有一个
            if (txtID.Text.Trim()!=txtHZID.Text.Trim())
            {
                string sql = "select count(*) from ZS_FAMILY where id='" + txtHZID.Text.Trim() + "' and 申请类型='" + txt申请类型.Text.Trim() + "' and sid='" + txtSID.Text.Trim() + "'";
                int count = Convert.ToInt32(_EluZSDataProvider.GetString(sql));
                if (count > 0)
                {
                    if (ddl关系.SelectedValue == "1")
                    {
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('户主只能有一个')</script>");
                        return;
                    }
                }
            }
            else
            {
                //修改申请表的人员信息
                string tablename = txtTABLENAME.Text.Trim();
               
            }           
                PersistenceControl1.Update();
                Antu.Utilities.UtilitiesPage.AlertDialog("保存成功！", "window.opener.RefreshForm();self.close();");
            
            
        }
    }
}
